﻿using System;
using GraphProcessor;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.Battle, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_Battle : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.Battle;
        public override string name => LevelEditorConst.Battle;

        [Output("敌方", false)] public EditorLevelServiceTargetSetter monsterTeam;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.Battle, "战斗类型")]
        public int battleType = -1;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_Battle()
            {
                battleType = this.battleType
            };

            this.monsterTeam = new EditorLevelServiceTargetSetter
                ((x) => rConfig.monsterTeam = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_Battle rNode)
            {
                this.battleType = rNode.battleType;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_Battle rConfig)
            {
                this.SyncDynamic(rConfig.monsterTeam, nameof(monsterTeam));
            }
        }
    }
}